package com.dh.project.utils;

import java.util.Random;

/**
 * Created by Administrator on 2017/8/25.
 */
public class CodeUtil {
/*public static String getFour() {

    Random r = new Random();
   int tag[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    String four = "";
    int temp = 0;
    while (four.length() != 4) {
        temp = r.nextInt(10);//随机获取0~9的数字
        if (tag[temp] == 0) {
            four += temp;
            tag[temp] = 1;
        }
    }

    return "{\"code\":\""+four+"\"}";


   // System.out.println(new Integer(r.nextInt(10)).toString()+new Integer(r.nextInt(10)).toString()+new Integer(r.nextInt(10)).toString()+new Integer(r.nextInt(10)).toString());
}*/

    public static Integer getFourCode() {

        Random r = new Random();
        int tag[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        String four = "";
        int temp = 0;
        while (four.length() != 4) {
            temp = r.nextInt(10);//随机获取0~9的数字
            if (tag[temp] == 0) {
                four += temp;
                tag[temp] = 1;
            }
        }

        return Integer.parseInt(four);


        // System.out.println(new Integer(r.nextInt(10)).toString()+new Integer(r.nextInt(10)).toString()+new Integer(r.nextInt(10)).toString()+new Integer(r.nextInt(10)).toString());
    }

    public static Integer getSixCode(){
        int min = 100000;
        int max = 999999;
        Random rand= new Random();
        int tmp = Math.abs(rand.nextInt());
        return tmp % (max - min + 1) + min;
    }

    /*public static String getSix(){
        int min = 100000;
        int max = 999999;
        Random rand= new Random();
        int tmp = Math.abs(rand.nextInt());
        Integer t = tmp % (max - min + 1) + min;

       return  "{\"code\":\""+t.toString()+"\"}";
    }*/

    public static String getJsonCode(int code){
        return "{\"code\":"+code+"}";
    }

    public static String getJsonCode(String code){
        return "{\"code\":"+code+"}";
    }
}
